package com.example.hellondk;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import com.example.hellondk.databinding.ActivityMainBinding;
import com.example.nativelib.NativeLib;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'hellondk' library on application startup.
    static {
        System.loadLibrary("hellondk");
    }

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Example of a call to a native method
        TextView tv = binding.sampleText;
        tv.setText(stringFromJNI());

        int sum = addNumbers(5, 10);
        binding.sampleText.append("\nSum: " + sum);

        // nativelib from nativelib-release.aar
        // NativeLib mylib = new NativeLib();
        binding.sampleText.append(String.format("\n%s", NativeLib.stringFromJNI()));
        binding.sampleText.append("\nSum from nativelib: " + NativeLib.addNumbers(2, 3));
    }

    /**
     * A native method that is implemented by the 'hellondk' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
    // 导出函数
    public native int addNumbers(int a, int b);
}